/**  
 * All rights Reserved, Designed By www.flksh.com
 * @date:   2017-11-06 10:09:04   
 * @Copyright: 2013-2017 www.flksh.com Inc. All rights reserved. 
 * 注意：本内容仅限于上海福乐康社区养老服务有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
package com.zx.cloud.controller;

import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.zx.cloud.ApiVersion;
import com.zx.cloud.RequestLogging;
import com.zx.cloud.util.Page;
import com.zx.cloud.common.filter.CurrentUserId;
import com.zx.cloud.domain.Consultation;
import com.zx.cloud.model.response.ObjectDataResponse;
import com.zx.cloud.model.response.Response;
import com.zx.cloud.service.ConsultationService;

/**
 * 公告
 */
@RestController
@RequestMapping(value = ApiVersion.PROVIDER_V1_PREFIX+"/consultation")
public class ConsultationController {

	private static final Logger logger = Logger
			.getLogger(ConsultationController.class);

	@Autowired
	private ConsultationService consultationService;

	// 查看公告表内容
	@RequestLogging
	@ApiOperation(value = "查看公告表内容" , notes = "查看公告表内容")
	@RequestMapping(value = "queryConsultation", method = RequestMethod.POST)
	@ResponseBody
	public Response queryConsultation(@CurrentUserId Long userId,
			@RequestBody Consultation consultation) {
		consultation.setOrderBy("create_time desc");
		Page<Consultation> datas = consultationService.page(consultation);
		return new ObjectDataResponse<Page<Consultation>>(datas);
	}

	// 修改公告信息
	@RequestLogging
	@ApiOperation(value = "修改公告表内容" , notes = "修改公告表内容")
	@RequestMapping(value = "updateConsultation", method = RequestMethod.POST)
	@ResponseBody
	public Response updateConsultation(@CurrentUserId Long userId,
			HttpServletRequest request, @RequestBody Consultation consultation) {
		int success = consultationService.update(consultation);
		return new ObjectDataResponse<Integer>(success);
	}

	// 添加公告信息
	@RequestLogging
	@ApiOperation(value = "添加公告表内容" , notes = "添加公告表内容")
	@RequestMapping(value = "addConsultation", method = RequestMethod.POST)
	@ResponseBody
	public Response addConsultation(@CurrentUserId Long userId,
			HttpServletRequest request, @RequestBody Consultation consultation) {
		consultation.setUserId(userId);
		int success = consultationService.insert(consultation);
		return new ObjectDataResponse<Integer>(success);
	}
	
	// 删除公告信息
	@RequestLogging
	@ApiOperation(value = "删除公告表内容" , notes = "删除公告表内容")
	@RequestMapping(value = "deleteConsultation", method = RequestMethod.POST)
	@ResponseBody
	public Response deleteConsultation(@CurrentUserId Long userId,
			HttpServletRequest request, @RequestBody Consultation consultation) {
		int success = consultationService.remove(consultation);
		return new ObjectDataResponse<Integer>(success);
	}

}
